package 力扣日常刷题.木22二月.第08天214;

/**
 * @author 帅小伙
 * @date 2022/2/14
 * @description
 */
public class Demo59合并数组 {


    public static void main(String[] args) {
        merge(new int[]{1,2,3,0,0,0},3,new int[]{2,5,6},3);
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] ans = new int[m + n];
        int i = 0, j = 0;
        while(i < m && j < n) {
            if(nums1[i] <= nums2[j]) ans[i+j] = nums1[i++];
            else ans[i+j]  = nums2[j++];
        }
        while(i < m) ans[i+j] = nums1[i++];
        while(j < n) ans[i+j] = nums2[j++];
        for (int k = 0; k < n+m; k++) {
            nums1[k] = ans[k];
        }

    }
}
